<?php	
namespace Shopmodule\Model;
use Think\Model;
class RangeTimeModel{
	public function rangemin($i){
		$minuts = date("i",time());
		$seconds = 60-date("s",time());
		$countdown = $i-$minuts%$i-1;
		$this->countdown = (60*($countdown)+$seconds)*1000;
	}
	public function range10(){
		$this->rangemin(10);
	}
	public function range20(){
		$this->rangemin(20);
	}
	public function range30(){
		$this->rangemin(30);
	} 
	public function range1h(){
		$minuts = date("i",time());
		$seconds = 60-date("s",time());
		$countdown = 60-$minuts-1;
		$this->countdown = (60*($countdown)+$seconds)*1000;
	}
	//支持 10、20、30分钟、1小时, 计划支持24小时
	public function getrangetime($range,$ts){
		switch($range){
			case 1:
				$minuts = date("i",$ts);
				$mm = (int)($minuts / 10);
				$rangetime = date("Y-m-d H:",$ts).$mm."0:00";
			break;
			case 2:
				$minuts = date("i",$ts);
				$mm = (int)($minuts / 20);
				$rangetime = date("Y-m-d H:",$ts).$mm."0:00";
			break;
			case 3:
				$minuts = date("i",$ts);
				$mm = (int)($minuts / 30);
				$rangetime = date("Y-m-d H:",$ts).$mm."0:00";
			break;
			case 4:
				$rangetime = date("Y-m-d H:",$ts)."00:00";
			break;
		}
		return $rangetime;
	}
	//2小时在前端不支持
	public function range2h(){
		$minuts = date("i",time());
		$seconds = 60-date("s",time());
		$countdown = 120-$minuts-1;
		$this->countdown=(60*($countdown)+$seconds)*1000;
	}
	
	public function range24h(){
		$minuts = date("i",time());
		$seconds = 60-date("s",time());
		$countdown = 60*24-$minuts-1;
		$this->countdown=(60*($countdown)+$seconds)*1000;
	}
}